This code collates data via the NY Times COVID-19 tracking project by relevant counties. Results are updated every day at 4:00 PM EST.
Use the table of contents on the left to navigate to your state. Then, click the appropriate tab to select your county.
Risk assessments for each county are set according to Harvard Global Health Institute parameters. For reference and comparison, you can view their tool at https://globalepidemics.org/key-metrics-for-covid-suppression/.
library(readr)
library(tidyverse)
library(usmap)
library(viridis)
library(scales)
library(sf)
library(plotly)
library(patchwork)
library(kableExtra)
#Get past and today's COVID data
todayDataURL = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/live/us-counties.csv'
today_covid_data = read_csv(url(todayDataURL))
pastDataURL = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv'
past_covid_data = read_csv(url(pastDataURL))
cum_covid_data = rbind(past_covid_data, select(today_covid_data, c("date", "county", "state", "fips", "cases", "deaths")))
cum_covid_data = cum_covid_data[with(cum_covid_data, order(date, state, county)),]
# cum_covid_data = cum_covid_data %>%
# filter(date > as.Date("2020-04-30"))
# NYT data lumps NYC boroughs together, so need to manually create those counties to plot. For simplicity's sake, I'm just assigning the total NY count to all boroughs
NYCdata = cum_covid_data %>%
filter(county == "New York City")
Manhattan = NYCdata
Manhattan$fips = 36061
Manhattan$county = "Manhattan"
Bronx = NYCdata
Bronx$fips = 36005
Bronx$county = "Bronx"
Queens = NYCdata
Queens$fips = 36081
Queens$county = "Queens"
Brooklyn = NYCdata
Brooklyn$fips = 36047
Brooklyn$county = "Brooklyn"
Staten_Island = NYCdata
Staten_Island$fips = 36085
Staten_Island$county = "Staten Island"
cum_covid_data = rbind(cum_covid_data, Manhattan, Bronx, Queens, Brooklyn, Staten_Island)
cum_covid_data = cum_covid_data[with(cum_covid_data, order(date, state, county)),]
#Get dates
today_date = cum_covid_data$date[nrow(cum_covid_data)]-1 #CHECK THIS!! yes, it appears that current data lags behind a day
today_date_MDY = format(today_date, format="%B %d %Y")
yesterday_date = cum_covid_data$date[nrow(cum_covid_data)]-7#-2 #CHECK THIS!!
yesterday_date_MDY = format(yesterday_date, format="%B %d %Y")
#Compute today's new cases
yesterday_covid_data = filter(cum_covid_data, date == today_date-7)#-2)
today_covid_data2 = filter(cum_covid_data, date == today_date-1) #today's data with modified NYC data
#today (6/22/2020), the NYC data for today and yesterday are the same....sooo check that. As of right now I'm using -2 and -1 days
#Merge Dataframes
new_case_data = merge(yesterday_covid_data, today_covid_data2, by = "fips")
data(countypop) # Using 2015 census estimates provided by usmap package. It's just easier.
new_case_data = merge(new_case_data, countypop, by = "fips")
new_case_data = new_case_data %>%
mutate(new_cases = ((cases.y - cases.x)/7)/pop_2015*100000) #Taking 7 day average here)
# Create USA MAP: TOTAL CASES
states <- plot_usmap("states", color = "black", fill = alpha(0.01), size = 1)
counties_total <- plot_usmap(data = today_covid_data2, values = "cases", color = "black", size = 0.5)
USA_map_total = ggplot() +
counties_total$layers[[1]] + #counties needs to be on top of states for this to work
states$layers[[1]] +
counties_total$theme +
coord_equal()+
scale_fill_viridis(limits = c(0, 3000), oob = squish, breaks = c(0, 1000, 2000, 3000), labels = c("0", "1000", "2000", ">3000"))+
labs(fill = "Total cases")+
theme(legend.position = "right",
plot.title = element_text(hjust = 0.5, size = 14))+
ggtitle(paste('Total Cases:', today_date_MDY))
# Create USA MAP: NEW CASES
counties_new <- plot_usmap(data = new_case_data, values = "new_cases", color = "black", size = 0.5)
USA_map_new = ggplot() +
counties_new$layers[[1]] + #counties needs to be on top of states for this to work
states$layers[[1]] +
counties_new$theme +
coord_equal()+
scale_fill_viridis(limits = c(0, 25), oob = squish, breaks = c(0, 5, 10, 15, 20, 25), labels = c("0", "5", "10", "15", "20", ">25"))+
labs(fill = "New cases (per 100k)")+
theme(legend.position = "right",
plot.title = element_text(hjust = 0.5, size = 14))+
ggtitle(paste('New Cases per 100,000 residents: ', yesterday_date_MDY, "-", today_date_MDY, sep = ""))
USA_map_total
USA_map_new
MA_map = plot.state("MA")
MA_map
MA_Essex = info.county("Massachusetts", "Essex", 25009)
risk_level = MA_Essex[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = MA_Essex[[7]]
ESSEX COUNTY SUMMARY:
MA_Essex[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
MA_Essex[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
MA_Suffolk = info.county("Massachusetts", "Suffolk", 25025)
risk_level = MA_Suffolk[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = MA_Suffolk[[7]]
SUFFOLK COUNTY SUMMARY:
MA_Suffolk[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
MA_Suffolk[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
MA_Middlesex = info.county("Massachusetts", "Middlesex", 25017)
risk_level = MA_Middlesex[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = MA_Middlesex[[7]]
MIDDLESEX COUNTY SUMMARY:
MA_Middlesex[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
MA_Middlesex[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
MA_Barnstable = info.county("Massachusetts", "Barnstable", 25001)
risk_level = MA_Barnstable[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = MA_Barnstable[[7]]
BARNSTABLE COUNTY SUMMARY:
MA_Barnstable[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
MA_Barnstable[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
NH_map = plot.state("NH")
NH_map
NH_Rockingham = info.county("New Hampshire", "Rockingham", 33015)
risk_level = NH_Rockingham[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = NH_Rockingham[[7]]
ROCKINGHAM COUNTY SUMMARY:
NH_Rockingham[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
NH_Rockingham[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
NH_Hillsborough = info.county("New Hampshire", "Hillsborough", 33011)
risk_level = NH_Hillsborough[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = NH_Hillsborough[[7]]
HILLSBOROUGH COUNTY SUMMARY:
NH_Hillsborough[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
NH_Hillsborough[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
VA_map = plot.state("VA")
VA_map
VA_Richmond = info.county("Virginia", "Richmond", 51159)
risk_level = VA_Richmond[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = VA_Richmond[[7]]
RICHMOND COUNTY SUMMARY:
VA_Richmond[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
VA_Richmond[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
MD_map = plot.state("MD")
MD_map
MD_Worcester = info.county("Maryland", "Worcester", 24047)
risk_level = MD_Worcester[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = MD_Worcester[[7]]
WORCESTER COUNTY SUMMARY:
MD_Worcester[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
MD_Worcester[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
MD_Anne_Arundel = info.county("Maryland", "Anne Arundel", 24003)
risk_level = MD_Anne_Arundel[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = MD_Anne_Arundel[[7]]
ANNE ARUNDEL COUNTY SUMMARY:
MD_Anne_Arundel[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
MD_Anne_Arundel[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
NC_map = plot.state("NC")
NC_map
NC_Guilford = info.county("North Carolina", "Guilford", 37081)
risk_level = NC_Guilford[[6]] # for some reason text_spec() doesn't like list objects, so need to assign these to their own variables.
risk_color = NC_Guilford[[7]]
GUILFORD COUNTY SUMMARY:
NC_Guilford[[4]]
New cases since beginning of pandemic. Bars represent new cases each day. Line represents the 7-day moving average
NC_Guilford[[5]]
New cases in past 30 days. Bars represent new cases each day. Line represents the 7-day moving average
A work by Phillip C. Desrochers
philcd89@gmail.com